package org.raymond.iworks.study.mq.kafka.controller;

import lombok.extern.slf4j.Slf4j;
import org.raymond.iworks.study.mq.kafka.common.Foo1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private KafkaTemplate<Object, Object> template;

    @PostMapping(path = "/send/{what}")
    public void sendFoo(@PathVariable String what) {
        log.info("what:{}", what);
        //this.template.send("demo1", what);
        //this.template.send("demo2", what);
        //this.template.send("demo4", new Foo1(what));
        //this.template.send("demo5", new Foo1(what));
        this.template.send("demo6", new Foo1(what));
    }

    /*
    @PostMapping(path = "/send/avro/{what}")
    public void sendAvro(@PathVariable String what) {
        log.info("what:{}", what);
        Long current = Instant.now().toEpochMilli();
        LogModel logModel = new LogModel();
        logModel.setId(3);
        logModel.setRequestIP("ip");
        logModel.setRequestURI("uri");
        logModel.setMethod("post");
        logModel.setClientTime(current);
        logModel.setHeaders("headers");
        logModel.setParams("params");
        logModel.setStatus("200");
        logModel.setStartTime(current);
        logModel.setEndTime(current);
        logModel.setRequest(what);
        this.template.send("demo3", logModel);
    }
     */
}
